package com.kris.controller;

import com.kris.model.ConstellationDomain;
import com.kris.model.UserDomain;
import com.kris.model.system.ResultModel;
import com.kris.service.ConstellationService;
import com.kris.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by Administrator on 2017/8/16.
 */
@Controller
public class UserController {

    @Autowired
    private UserService userService;

    @Autowired
    private ConstellationService constellationService;

    @ResponseBody
    @RequestMapping("/queryConstellation")
    public ResultModel getConstellation(@RequestBody UserDomain user) {
        ConstellationDomain constellationDomain = new ConstellationDomain();
        ResultModel resultModel = new ResultModel();
        try {
            if (user.getUserName() != null && user.getBirthday() != null) {
                userService.addUser(user);
                constellationDomain = constellationService.getConstellation(user.getBirthday());
            }
            resultModel.success(constellationDomain);
        } catch (Exception e) {
            e.printStackTrace();
            resultModel.error();
        }
        return resultModel;
    }


    @RequestMapping({"/index","/"})
    public String index() {
        return "page/dist/index";
    }

    @ResponseBody
    @RequestMapping("/all")
    public Object findAllUser(
            @RequestParam(name = "pageNum", required = false, defaultValue = "1")
                    int pageNum,
            @RequestParam(name = "pageSize", required = false, defaultValue = "10")
                    int pageSize) {
        return userService.findAllUser(pageNum, pageSize);
    }

}
